<!doctype html>
<html>
<head>
	<meta charset="utf-8"><meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<title>课堂</title>
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
</head>
<body>
<div id="root">
	<div class="app_warp">
		<div class="app_head">
			<span class="left back"></span>
			<span class="name">课程详情</span>
			<span class="right share" tapmode onclick="$('#share').toggle()"></span>
		</div>
		<div class="app_main">
			<div id="nocontent" class="nocontent animated fadeInUp">
				<img src="../../lib/img/loading.gif" class="minimize" alt="">
				<div class="text minimize">
					准备数据
				</div>
			</div>
		</div>
		<div id="share" style="display: none" tapmode onclick="$('#share').hide()">
			<div class="inner_shere">
				<p class="clearfix">
					<span class="wxfriend" tapmode onclick="share_wxfriend()"></span>
					<span class="wx"  tapmode onclick="share_wx()"></span>
					<span class="wb" tapmode onclick="share_wb()"></span>
				</p>
				<a href="javascript:;" class="skin_btn">取消</a>
			</div>
		</div>
	</div>
</div>
<script id="classroom_view_template" type="text/html">

	<div class="video_row" style="background-image: url('<%:=data.verb.cover%>')">
		<span class="play"></span>
		<span class="intro">获得积分+<span>200</span>以上可以播放此视频。</span>
		<a href="javascript:;">如何获得积分</a>
	</div>

	<div class="app_col_nav clearfix">
		<div class="app_col_inner_nav loaded menuflex">
			<a href="javascript:;" class="active" tapmode onclick="viewContent(this,0)">简介</a>
			<a href="javascript:;" tapmode onclick="viewContent(this,1)">目录</a>
			<a href="javascript:;" tapmode onclick="viewContent(this,2)">评价</a>
		</div>
	</div>
	<div class="app_main">

		<div class="app_main_content video_intro animated fadeInUp">

			<div class="space"></div>

			<div class="app_box">
				<div class="box_tit">
					<span class="name h">
						<%:=data.verb.title%>
					</span>
				</div>
				<div class="box_cont content_box">
					<div class="video_intro_intro">
						<%:=data.verb.introduction%>
						<br>
						<%:=data.verb.ophourNum%>课时
					</div>
				</div>
			</div>

			<div class="app_box">
				<div class="box_tit">
					<span class="name h">
						主讲
					</span>
				</div>
				<div class="box_cont content_box">
					<div class="video_intro_author">
						<img class="imgcache" src="<%:=img%>" data_src="<%:=data.verb.avatar%>" alt="">
						<%:=data.verb.author%>
					</div>
					<div class="video_intro_intro">
						<%:=data.verb.sitd%>
					</div>
				</div>
			</div>

		</div>
		<div class="app_main_content video_menu hide animated fadeInUp">

			<div class="space"></div>

			<div class="app_box">
				<div class="box_cont content_box">

					<ul class="video_menu_list">
						<% for(var i in data.ophour){ var _data_ = data.ophour[i] %>
						<li class="video_menu_item <%:=(i==0?'active':'')%>" tapmode onclick="setVideoIntro(<%:=i%>)">
							<%:=_data_.catalog%>
							<span class="tag">
								<%:=(_data_.power==0?'免积分':_data_.power+'积分')%>
							</span>
							<span class="timer">
								<%:=_data_.timer%>
							</span>
						</li>
						<% } %>
					</ul>
				</div>
			</div>
		</div>
		<div class="app_main_content video_reply hide animated fadeInUp">

			<div class="space"></div>
			<%if(!data.comment){%>
			<ul id="video_comment_list" class="list_item line_list clearfix">
				<li class="nocontent por animated fadeInUp">
					<img src="../../lib/img/nocomment.png" alt="">
					<div class="text">
						还没有评论
					</div>
				</li>
			</ul>
			<%}else{%>
			<ul id="video_comment_list" class="video_comment_list">
				<% for(var j in data.comment){ var _comment_ = data.comment[j] %>
				<li class="video_comment_item" data_id="<%:=_comment_.id%>">
					<div class="avatar">
						<img class="imgcache" src="<%:=img%>" data_src="<%:=_comment_.avatar%>" alt="">
						<span class="name"><%:=_comment_.author%></span>
						<%:=_comment_.date%>
					</div>
					<div class="intro">
						<%:=_comment_.intro%>
					</div>
				</li>
				<% } %>
			</ul>
			<%}%>
		</div>
	</div>

</script>
<script id="reply_template" type="text/html">
		<li class="video_comment_item" data_id="<%:=data.id%>">
			<div class="avatar">
				<img class="imgcache" src="<%:=img%>" data_src="<%:=data.avatar%>" alt="">
				<span class="name"><%:=data.author%></span>
				<%:=data.date%>
			</div>
			<div class="intro">
				<%:=data.intro%>
			</div>
		</li>
</script>
<script>
	var
		wx,
		pageData,
		classIndex=0,
		classid,
		wxShareOption={
			title:'来自您朋友的分享',
			description:'您的好友分享给您一条艺考消息',
			thumb:undefined,
			contentUrl:undefined
		},
		share_wxfriend=function(){
			wxShareOption.scene='session';
			wx.shareWebpage(wxShareOption , function(ret, err) {
				if (ret.status) {
					api.toast({
						msg:'分享成功'
					})
				} else {
					api.toast({
						msg:'分享失败code'+err.code
					})
				}
			});
		},share_wx=function(){
			wxShareOption.scene='timeline';
			wx.shareWebpage(wxShareOption , function(ret, err) {
				if (ret.status) {
					api.toast({
						msg:'分享成功'
					})
				} else {
					api.toast({
						msg:'分享失败code'+err.code
					})
				}
			});
		},share_wb=function(){
			//当contentType为music,video或webpage时，内容地址不能为流媒体地址;
			var sinaWeiBo = api.require('sinaWeiBo');
			sinaWeiBo.sendRequest({
				contentType: 'web_page',
				media: {
					title: wxShareOption.title,
					description: wxShareOption.description,
					thumbUrl: wxShareOption.thumb,
					webpageUrl: wxShareOption.contentUrl
				}
			}, function(ret, err) {
				if (ret.status) {
					api.toast({
						msg:'分享成功'
					})
				} else {
					api.toast({
						msg:'分享失败code'+err.code
					})
				}
			});
		},
		//显示tab点击后应该显示的内容
		viewContent = function (obj, win) {
			if (!$(obj).hasClass('active')) {
				$('.app_col_inner_nav a').removeClass('active')
				$(obj).addClass('active');
				$('.app_main_content').addClass('hide').eq(win).removeClass('hide');
			}
		},
		//页面数据输出的方法
		initPage=function(data,init){
			_$.template('classroom_view_template', {
				data: data.data,
				img: _$.imgCache.default
			}, function (html) {
				wx = api.require('wx');
				if(init===true){
					$('.app_main').replaceWith(html);
					$('.app_main').after('' +
						'<div class="commentline">' +
						'   <div class="myinput" tapmode onclick="_$.sendComment(\'comment\',\'发表评价\',classid)">' +
						'       我来说一说' +
						'   </div>' +
						'   <div class="shoucang '+(data.data.verb.collect===true?'active':'')+'" tapmode onclick="shoucang(this,'+data.data.verb.id+')">' +
						'       收藏' +
						'   </div>' +
						'</div>' +
						'');
				}else{
					$('.app_main').replaceWith(html);
				}
				_$.imgCache.load();
			})
		},
		comment_ajaxCall=function(data){
			data = data.data.comment.pop();
			_$.template('reply_template', {
				data: data,
				img: _$.imgCache.default
			}, function (html) {
				$('#video_comment_list .nocontent').remove();
				$('#video_comment_list').prepend(html).addClass('video_comment_list').removeClass('list_item line_list');
				_$.imgCache.load();
			})
		},
		//评论后的回调内容
		callInit=function(data){
			pageData.comment = data;
			initPage(pageData);
		},
		//收藏动作的脚本
		shoucang = function (obj, id) {
			_$.ajax({
				interface: 'setCollect',
				data: {
					aid: id,
					type: 1
				},
				call: function (data) {
					if (data.status === 200) {
						$(obj).toggleClass('active');
						api.toast({
							msg: data.msg
						})
					} else {
						api.toast({
							msg: '操作失败'
						})
					}
				}
			})
		},
		//检查视频是否具备播放的条件
		setVideoIntro=function(index){

			if(index===classIndex){
				return;
			}

			if(index!==undefined){
				classIndex = index;
				$('.video_menu_list li').removeClass('active').eq(index).addClass('active');
			}

			var video = pageData.data.ophour[classIndex].video,
				status=(video===null?false:true),
				power = pageData.data.ophour[classIndex].power,
				clickobj = $('.video_row').removeClass('active');

			clickobj.off('click');

			$('.video_row .intro,.video_row a').hide();

			if(status===false){
				$('.video_row .intro span').html(power);
				$('.video_row .intro,.video_row a').show();
				clickobj.off('click').on('click',function(){
					api.openWin({
						name:'jifen',
						url:'../user/jifen.html'
					})
				});
			}else{
				clickobj.addClass('active');
				clickobj.off('click').on('click',function(){
					api.openWin({
						name:'play',
						url:'../search/play.html',
						pageParam:{
							path:video
						}
					})
				});
			}
		},
		appready = function () {
			//加载指定id的课程内容
			_$.ajax({
				interface: 'getClassDetails',
				data: {
					id: api.pageParam.id
				},
				call: function (data) {
					classid = api.pageParam.id;
					if (data.status === 200) {
						wxShareOption={
							title:data.data.verb.title,
							description:data.data.verb.introduction,
							thumb:data.data.verb.cover,
							contentUrl:data.data.verb.url
						}
						$('.app_head .name').text(_$.subStr(data.data.verb.title, 8, '...'));
						pageData = data;
						initPage(pageData,true);
						setVideoIntro();
					} else {
						wxShareOption=false;
						api.toast({
							msg: data.msg
						})
						_$.sleep(function () {
							api.closeWin()
						}, 3000);
					}
				}
			})
		};

</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/swiper.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>